export function myTreeDataUtils (data, viewData) {
  let dataList = [];
  if (data) {
    for (let index = 0; index < data.length; index++) {
      let firstFlag = false;
      let lastFlag = false;

      if (data[index].subList && data[index].subList.length > 0) {
        data[index].subList = myTreeDataUtils(data[index].subList, viewData);
      }
      let param = {
        'title': data[index].categoryName,
        'uuid': data[index].uuid,
        'levelNum': data[index].levelNum,
        'parentUuid': data[index].parentUuid,
        expand: true,
        children: data[index].subList,
        _showChildren: true,
      }
      dataList.push(param)
    }
  }
  return dataList;
}

export function jibenTreeDataUtils (data, viewData) {
  let dataList = [];
  if (data) {
    for (let index = 0; index < data.length; index++) {
      if (data[index].twoList && data[index].twoList.length > 0) {
        data[index].twoList = jibenTreeDataUtils(data[index].twoList, viewData);
      }
      let param = {
        'title': data[index].sceneName,
        'uuid': data[index].sceneUuid,
        'levelNum': data[index].levelNum,
        'parentUuid': data[index].parentUuid,
        checked: data[index].choose === 'Y' ? true : false,
        expand: true,
        children: data[index].twoList,
        choose: data[index].choose,
        _showChildren: true,
      }
      dataList.push(param)
    }
  }
  return dataList;
}

export function jibenTreeDataUtilsNot (data, viewData) {
  let dataList = [];
  if (data) {
    for (let index = 0; index < data.length; index++) {
      if (data[index].twoList && data[index].twoList.length > 0) {
        data[index].twoList = jibenTreeDataUtilsNot(data[index].twoList, viewData);
      }
      let param = {
        'title': data[index].sceneName,
        'uuid': data[index].sceneUuid,
        'levelNum': data[index].levelNum,
        'parentUuid': data[index].parentUuid,
        checked: data[index].choose === 'Y' ? true : false,
        expand: true,
        disabled: true,
        children: data[index].twoList,
        choose: data[index].choose,
        _showChildren: true,
      }
      dataList.push(param)
    }
  }
  return dataList;
}

export function cityTreeDataUtils (data, viewData) {
  let dataList = [];
  if (data) {
    for (let index = 0; index < data.length; index++) {
      if (data[index].cityList && data[index].cityList.length > 0) {
        data[index].cityList = cityTreeDataUtils1(data[index].cityList, viewData);
      }
      let param = {
        'title': data[index].provinceName,
        'uuid': data[index].provinceUuid,
        'code': data[index].provinceCode,
        'position': data[index].position,
        expand: true,
        children: data[index].cityList,
        _showChildren: true,
        checked: data[index].selected,
      }
      dataList.push(param)
    }
  }
  return dataList;
}

export function cityTreeDataUtils1 (data, viewData) {
  let dataList = [];
  if (data) {
    for (let index = 0; index < data.length; index++) {
      let param = {
        'title': data[index].cityName,
        'uuid': data[index].cityUuid,
        'code': data[index].cityCode,
        'position': data[index].position,
        expand: true,
        _showChildren: true,
        checked: data[index].selected,
      }
      dataList.push(param)
    }
  }
  return dataList;
}


export function newCityTreeDataUtils (data, viewData) {
  let dataList = [];
  if (data) {
    for (let index = 0; index < data.length; index++) {
      if (data[index].cityList && data[index].cityList.length > 0) {
        data[index].cityList = newCityTreeDataUtils1(data[index].cityList, viewData);
      }
      let param = {};
      param = {
        'title': data[index].provinceName,
        'uuid': data[index].provinceUuid,
        'code': data[index].provinceCode,
        'position': data[index].position,
        expand: true,
        children: data[index].cityList,
        _showChildren: true,
        checked: data[index].selected,
      }
      dataList.push(param)
    }
  }
  return dataList;
}

export function newCityTreeDataUtils1 (data, selectedCityCodeList) {
  let dataList = [];
  if (data) {
    for (let index = 0; index < data.length; index++) {
      	  
	  let checkedFlag = false; //默认没选中
	  if(selectedCityCodeList !==undefined
			&& selectedCityCodeList != ''
			&& selectedCityCodeList.length > 0 ) {
		  for (let indexI = 0; indexI < selectedCityCodeList.length; indexI++) {
			  if(data[index].cityCode==selectedCityCodeList[indexI]){
				  checkedFlag = true; //选中
			  }	  
		  } 
	  }
	   	  
      let param = {
          'title': data[index].cityName,
          'uuid': data[index].cityUuid,
          'code': data[index].cityCode,
          'position': data[index].position,
          expand: true,
          _showChildren: true,
          checked: checkedFlag,
        }
      
      dataList.push(param)
    }
  }
  return dataList;
}

export function formatZero (num) {
  if (String(num).length > 3) return num;
  return (Array(3).join(0) + num).slice(-3);
}

